﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using Medianamik.Core;
using NUnit.Framework;
using Tests.Integration.Medianamik;

namespace Tests.Integration_Medianamik
{
    [TestFixture]
   public class TransacSaveTests
    {
        [TestFixtureSetUp]
        public void TestFixtureSetUp()
        {
            TestUtils.TestFixtureSetUp();
        }

        [TestFixtureTearDown]
        public void TestFixtureTearDown()
        {
            TestUtils.TestFixtureTearDown();
        }

        [SetUp]
        public void SetUp()
        {
            TestUtils.SetUp();
        }

        [TearDown]
        public void TearDown()
        {
            TestUtils.TearDown();
        }

        [Test]
        public void CreateNewNodeWithCultureInvariantPropertiesAndCultureVariantProperties()
        {
            const string value = "salut";
            var newNode = TestUtils.CreateNode(Constants.NodeTypes.ContentPage, Constants.Nodes.WebSite, "Test");
            newNode["fr-ca"]["NeutralProperty"].SetValue(value);

            NodeManager.SaveApproveAndPublishNode(newNode, CultureInfo.GetCultureInfo("fr-ca"));

            try
            {
                var node = NodeManager.GetNode(newNode.NodeId);
                Assert.That(node["fr-ca"]["NeutralProperty"].GetValue<string>(), Is.EqualTo(value));

                node["fr-ca"]["NeutralProperty"].SetValue("bye");
                NodeManager.SaveApproveAndPublishNode(node, CultureInfo.GetCultureInfo("fr-ca"));
            }
            finally
            {
                NodeManager.DestroyNode(newNode);
            }
        }
    }
}
